<template>
  <pro-layout
    v-bind="settings"
    layout="side"
    headerTheme="light"
    navTheme="light"
    :menu="{locale:false}"
    :menuData="menus"
    :collapsed="collapsed"
    :mediaQuery="query"
    :isMobile="isMobile"
    :handleMediaQuery="handleMediaQuery"
    :breadcrumbRender="handleBreadcrumbRender"
    :collapsedWidth="80"
    :siderWidth="210"
  >
    <!-- 1.0.0+ 版本 pro-layout 提供 API，
            我们推荐使用这种方式进行 LOGO 和 title 自定义
      -->
    <template v-slot:menuHeaderRender>
      <div>
        <img
          v-show="!collapsed"
          src="@/assets/svg/jeepay.svg"
          alt="jeepay"
          style="width: 90px; margin: 5px 0 0 5px"
        />
      </div>
    </template>
    <!-- 1.0.0+ 版本 pro-layout 提供 API,
            增加 Header 左侧内容区自定义
      -->
    <template v-slot:collapsedButtonRender>
      <div class="ant-pro-global-header-collapse"> 展开 </div>
    </template>
    <template v-slot:headerContentRender>
      <div class="ant-pro-global-header-trigger">
        <div class="ant-pro-global-header-left">
          <div class="ant-pro-global-header-option" @click="handleCollapse()">
            <menu-fold-outlined v-if="!this.collapsed"/>
            <menu-unfold-outlined v-else/>
          </div>
          <div class="ant-pro-global-header-option" @click="routeReload()"> 
            <a-tooltip title="刷新页面">
              <reload-outlined />
            </a-tooltip>
          </div>
        </div>
        <div class="ant-pro-global-header-right">
          <right-content
            :top-menu="settings.layout === 'topmenu'"
            :is-mobile="isMobile"
            :theme="settings.theme"
          />
        </div>
      </div>
    </template>

    <!-- <template v-slot:avatarProps>
      <right-content
        :top-menu="settings.layout === 'topmenu'"
        :is-mobile="isMobile"
        :theme="settings.theme"
      />
    </template> -->
    <!-- custom footer / 自定义Footer -->
    <template v-slot:footerRender>
      <global-footer />
    </template>
    <router-view v-if="isRouterAlive" />
  </pro-layout>
</template>

<script lang="jsx">
import { mapState } from 'vuex'
import RightContent from '@/components/GlobalHeader/RightContent'
import GlobalFooter from '@/components/GlobalFooter'
import appConfig from '@/config/appConfig'
import { ReloadOutlined, MenuFoldOutlined, MenuUnfoldOutlined,TeamOutlined} from '@ant-design/icons-vue'

export default {
  name: 'BasicLayout',
  components: {
    RightContent,
    GlobalFooter,
    ReloadOutlined,
    MenuFoldOutlined,
    MenuUnfoldOutlined,
    TeamOutlined
  },
  data () {
    return {
      isRouterAlive: true,
      // preview.pro.antdv.com only use.
      isProPreviewSite:
        process.env.VUE_APP_PREVIEW === 'true' &&
        process.env.NODE_ENV !== 'development',
      // end

      // base
      menus: [],
      // 侧栏收起状态
      collapsed: false,
      title: appConfig.APP_TITLE,
      settings: {
        // 布局类型
        layout: 'sidemenu', // 'sidemenu', 'topmenu'
        contentWidth: 'Fluid', // Fixed , Fluid  内容区布局： 固定  | 流式
        theme: 'light', // 主题 'dark' | 'light'
        // 主色调
        primaryColor: '#1a53fc', // 默认主题色, 如果修改颜色不生效，请清理 localStorage
        fixedHeader: false, // 固定 Header
        fixSiderbar: true, // 固定左侧菜单栏
        colorWeak: false, // 色盲模式将
        hideHintAlert: false,
        hideCopyButton: false,
        iconfontUrl: 'www.baidu.com',
        sider: {
          colorBgCollapsedButton: '#fff',
          colorTextCollapsedButtonHover: 'rgba(29,165,122,1)',
          colorTextCollapsedButton: 'rgba(255,255,255,0.45)',
          colorMenuBackground: '#fff',
          colorBgMenuItemCollapsedElevated: 'transparent',
          colorMenuItemDivider: 'rgba(0,0,0,1)',
          colorBgMenuItemHover: 'rgba(216,230,223,1)',
          colorBgMenuItemSelected: 'rgba(216,230,223,1)',
          colorTextMenuSelected: 'rgba(29,165,122,1)',
          colorTextMenuItemHover: 'rgba(29,165,122,1)',
          colorTextMenu: 'rgba(255,255,255,0.45)',
          colorTextMenuSecondary: 'rgba(255,255,255,0.45)',
          colorTextMenuTitle: 'rgba(255,255,255,0.45)',
          colorTextMenuActive: 'rgba(255,255,255,0.45)',
        },
      },
      // 媒体查询
      query: {},

      // 是否手机模式
      isMobile: false,
      tokenStyle: {
        sider: {
          colorBgCollapsedButton: '#fff',
          colorTextCollapsedButtonHover: 'rgba(29,165,122,1)',
          colorTextCollapsedButton: 'rgba(255,255,255,0.45)',
          colorMenuBackground: '#fff',
          colorBgMenuItemCollapsedElevated: 'transparent',
          colorMenuItemDivider: 'rgba(0,0,0,1)',
          colorBgMenuItemHover: 'rgba(216,230,223,1)',
          colorBgMenuItemSelected: 'rgba(216,230,223,1)',
          colorTextMenuSelected: 'rgba(29,165,122,1)',
          colorTextMenuItemHover: 'rgba(29,165,122,1)',
          colorTextMenu: 'rgba(255,255,255,0.45)',
          colorTextMenuSecondary: 'rgba(255,255,255,0.45)',
          colorTextMenuTitle: 'rgba(255,255,255,0.45)',
          colorTextMenuActive: 'rgba(255,255,255,0.45)',
        },
      }
    }
  },
  computed: {
    ...mapState({
      // 动态主路由
      mainMenu: (state) => state.asyncRouter.addRouters
    })
  },
  created () {
    const routes = this.mainMenu.find(item => item.path === '/')
    // this.menus = (routes && routes.children) || []
    this.menus = [
    {
        "path": "/ENT_COMMONS",
        "name": "ENT_COMMONS",
        "component": {
            "name": "RouteView",
            "props": {
                "keepAlive": {
                    "default": true
                }
            },
            "beforeCreate": [
                null
            ],
            "beforeDestroy": [
                null
            ],
            "__file": "src/layouts/RouteView.vue"
        },
        "meta": {
            "title": "系统通用菜单",
            "icon": "no-icon",
            "keepAlive": false
        },
        "hidden": true,
        "children": [
            {
                "path": "/current/userinfo",
                "name": "ENT_C_USERINFO",
                "meta": {
                    "title": "个人中心",
                    "icon": "no-icon",
                    "keepAlive": false
                },
                "hidden": true
            }
        ]
    },
    {
        "path": "/main",
        "name": "ENT_MCH_MAIN",
        "meta": {
            "title": "主页",
            "icon": "home-outlined",
            "keepAlive": false
        },
        "hidden": false
    },
    {
        "path": "/ENT_MCH_CENTER",
        "name": "ENT_MCH_CENTER",
        "component": {
            "name": "RouteView",
            "props": {
                "keepAlive": {
                    "default": true
                }
            },
            "beforeCreate": [
                null
            ],
            "beforeDestroy": [
                null
            ],
            "__file": "src/layouts/RouteView.vue"
        },
        "meta": {
            "title": "商户中心",
            "icon": "team-outlined",
            "keepAlive": false
        },
        "hidden": false,
        "children": [
            {
                "path": "/apps",
                "name": "ENT_MCH_APP",
                "meta": {
                    "title": "应用管理",
                    "icon": "appstore-add-outlined",
                    "keepAlive": false
                },
                "hidden": false
            },
            {
                "path": "/accountbill",
                "name": "ENT_MCH_ACCOUNT_BILL",
                "meta": {
                    "title": "账户明细",
                    "icon": "appstore-outlined",
                    "keepAlive": false
                },
                "hidden": false
            },
            {
                "path": "/draw",
                "name": "ENT_MCH_DRAW",
                "meta": {
                    "title": "提汇",
                    "icon": "appstore-outlined",
                    "keepAlive": false
                },
                "hidden": false
            }
        ]
    },
    {
        "path": "/ENT_ORDER",
        "name": "ENT_ORDER",
        "component": {
            "name": "RouteView",
            "props": {
                "keepAlive": {
                    "default": true
                }
            },
            "beforeCreate": [
                null
            ],
            "beforeDestroy": [
                null
            ],
            "__file": "src/layouts/RouteView.vue"
        },
        "meta": {
            "title": "订单中心",
            "icon": "transaction",
            "keepAlive": false
        },
        "hidden": false,
        "children": [
            {
                "path": "/pay",
                "name": "ENT_PAY_ORDER",
                "meta": {
                    "title": "订单管理",
                    "icon": "account-book",
                    "keepAlive": false
                },
                "hidden": false
            },
            {
                "path": "/transfer",
                "name": "ENT_TRANSFER_ORDER",
                "meta": {
                    "title": "转账订单",
                    "icon": "property-safety",
                    "keepAlive": false
                },
                "hidden": false
            }
        ]
    },
    {
        "path": "/ENT_SYS_CONFIG",
        "name": "ENT_SYS_CONFIG",
        "component": {
            "name": "RouteView",
            "props": {
                "keepAlive": {
                    "default": true
                }
            },
            "beforeCreate": [
                null
            ],
            "beforeDestroy": [
                null
            ],
            "__file": "src/layouts/RouteView.vue"
        },
        "meta": {
            "title": "系统管理",
            "icon": "setting",
            "keepAlive": false
        },
        "hidden": false,
        "children": [
            {
                "path": "/ENT_UR",
                "name": "ENT_UR",
                "component": {
                    "name": "RouteView",
                    "props": {
                        "keepAlive": {
                            "default": true
                        }
                    },
                    "beforeCreate": [
                        null
                    ],
                    "beforeDestroy": [
                        null
                    ],
                    "__file": "src/layouts/RouteView.vue"
                },
                "meta": {
                    "title": "用户角色管理",
                    "icon": "team",
                    "keepAlive": false
                },
                "hidden": false,
                "children": [
                    {
                        "path": "/users",
                        "name": "ENT_UR_USER",
                        "meta": {
                            "title": "操作员管理",
                            "icon": "contacts",
                            "keepAlive": false
                        },
                        "hidden": false
                    },
                    {
                        "path": "/roles",
                        "name": "ENT_UR_ROLE",
                        "meta": {
                            "title": "角色管理",
                            "icon": "user",
                            "keepAlive": false
                        },
                        "hidden": false
                    }
                ]
            }
        ]
    }
]
    
    console.log(this.menus,'this.menus')

    // 处理侧栏收起状态
    // this.$watch('collapsed', () => {
    //   this.$store.commit(SIDEBAR_TYPE, this.collapsed)
    // })
    // this.$watch('isMobile', () => {
    //   this.$store.commit(TOGGLE_MOBILE_TYPE, this.isMobile)
    // })
  },
  mounted () {
    const userAgent = navigator.userAgent
    if (userAgent.indexOf('Edge') > -1) {
      this.$nextTick(() => {
        this.collapsed = !this.collapsed
        setTimeout(() => {
          this.collapsed = !this.collapsed
        }, 16)
      })
    }
  },
  methods: {
    handleMediaQuery (val) {
      this.query = val
      if (this.isMobile && !val['screen-xs']) {
        this.isMobile = false
        return
      }
      if (!this.isMobile && val['screen-xs']) {
        this.isMobile = true
        this.collapsed = false
      }
    },
    handleCollapse () {
      this.collapsed = !this.collapsed
    },
    handleBreadcrumbRender (rrr) {
      debugger
      if (rrr.route.path.startsWith('/ENT')) {
        return <span>{rrr.route.breadcrumbName}</span>
      }
      return (
        <router-link to={rrr.route.path || '/'}>
          <span>{rrr.route.breadcrumbName}</span>
        </router-link>
      )
    },
    routeReload () {
      // 刷新页面函数
      this.isRouterAlive = false
      this.$nextTick(() => {
        this.isRouterAlive = true
      })
    },
  }
}
</script>

<style lang="less">
@import './BasicLayout.less';
</style>
